function apachecalc(immuno,arf,age,temp,ph,hr,rr,na,pot,creat,hct,wbc,gcs,unitchoice,o2){

var value=0;
var logit=0;
var expcalc=0;
var mort=0;	
	
//o2
if (unitchoice) {
if (o2 > 499)	  { value = value+4; }
if (350 <= o2 && o2 <= 499) { value = value+3; }
if (200 <= o2 && o2 < 350) { value = value+2; }
if (o2 < 200) 	  { value = value+0; }
}

if (!unitchoice) {
if (o2 > 70)	  { value = value+0; }
if (61 <= o2 && o2 <= 70) { value = value+1; }
if (55 <= o2 && o2 < 61) { value = value+3; }
if (o2 < 55) 	  { value = value+4; }
}

//gcs
gcs = 15-gcs;
value = value+gcs;

//wbc
if (wbc >= 40)	  { value = value+4; }
if (20 <= wbc && wbc < 40) { value = value+2; }
if (15 <= wbc && wbc < 20) { value = value+1; }
if (3 <= wbc && wbc < 15) { value = value+0; }
if (1 <= wbc && wbc < 3) { value = value+2; }
if (wbc < 1) 	  { value = value+4; }

//hct
if (hct > 59.9)	  { value = value+4; }
if (50 <= hct && hct <= 59.9) { value = value+2; }
if (46 <= hct && hct < 50) { value = value+1; }
if (30 <= hct && hct < 46) { value = value+0; }
if (20 <= hct && hct < 30) { value = value+2; }
if (hct < 20) 	  { value = value+4; }


//creatinine
if (arf == 1) {
if (creat > 305)	  { value = value+8; }
if (170 <= creat && creat <= 304) { value = value+6; }
if (130 <= creat && creat < 69) { value = value+4; }
if (54 <= creat && creat < 129) { value = value+0; }
if (creat < 54) 	  { value = value+2; }
}

if (arf == 0) {
if (creat > 305)	  { value = value+4; }
if (170 <= creat && creat <= 304) { value = value+3; }
if (130 <= creat && creat < 69) { value = value+2; }
if (54 <= creat && creat < 129) { value = value+0; }
if (creat < 54) 	  { value = value+2; }
}

//potassium
if (pot > 6.9)	  { value = value+4; }
if (6 <= pot && pot <= 6.9) { value = value+3; }
if (5.5 <= pot && pot < 6) { value = value+1; }
if (3.5 <= pot && pot < 5.5) { value = value+0; }
if (3 <= pot && pot < 3.5) { value = value+1; }
if (2.5 <= pot && pot < 3) { value = value+2; }
if (pot < 2.5) 	  { value = value+4; }

//sodium
if (na > 179)	  { value = value+4; }
if (160 <= na && na <= 179) { value = value+3; }
if (155 <= na && na < 159) { value = value+2; }
if (150 <= na && na < 155) { value = value+1; }
if (130 <= na && na < 150) { value = value+0; }
if (120 <= na && na < 130) { value = value+2; }
if (111 <= na && na < 120) { value = value+3; }
if (na < 111) 	  { value = value+4; }

//rr
if (rr > 49)	  { value = value+4; }
if (35 <= rr && rr <= 49) { value = value+3; }
if (25 <= rr && rr < 35) { value = value+1; }
if (12 <= rr && rr < 25) { value = value+0; }
if (10 <= rr && rr < 12) { value = value+1; }
if (6 <= rr && rr < 10) { value = value+2; }
if (rr < 6) 	  { value = value+4; }

//hr
if (hr > 179)	  { value = value+4; }
if (140 <= hr && hr <= 179) { value = value+3; }
if (110 <= hr && hr < 140) { value = value+2; }
if (70 <= hr && hr < 110) { value = value+0; }
if (55 <= hr && hr < 70) { value = value+2; }
if (40 <= hr && hr < 55) { value = value+3; }
if (hr < 40) 	  { value = value+4; }

//ph
if (ph > 7.69)	  { value = value+4; }
if (7.59 < ph && ph <= 7.69) { value = value+3; }
if (7.49 < ph && ph <= 7.59) { value = value+1; }
if (7.32 < ph && ph <= 7.49) { value = value+0; }
if (7.24 < ph && ph <= 7.32) { value = value+2; }
if (7.15 <= ph && ph <= 7.24) { value = value+3; }
if (ph < 7.15) 	  { value = value+4; }

//temp
if (temp < 30) 	  { value = value+4; }
if (30 <= temp && temp < 32) { value = value+3; }
if (32 <= temp && temp < 34) { value = value+2; }
if (34 <= temp && temp < 36) { value = value+1; }
if (36 <= temp && temp < 38.5) { value = value+0; }
if (38.5 <= temp && temp < 39) { value = value+1; }
if (39 <= temp && temp < 40.9) { value = value+3; }
if (temp >= 40.9)	  { value = value+4; }


//age 
if (age < 45) 	  { value = value+0; }
if (45 <= age && age < 55) { value = value+2; }
if (55 <= age && age < 65) { value = value+3; }
if (65 <= age && age < 75) { value = value+5; }
if (age >= 75)	  { value = value+6; }


value=value+immuno;

//Logit = -3,517+( Apache II) * 0,146
//Predicted Death Rate =eLogit/(1+eLogit

logit = -3.517 + (value*0.146);
expcalc=Math.exp(logit);
mort=expcalc/(1+expcalc);
mort=Math.round(100*mort);

return {
			 value:value,
			 mort:mort,
			 age:age
	};		 
}




function ref(){
// display reference
 return "Knaus WA, Draper EA, Wagner DP, Zimmerman JE. APACHE II: a severity of disease classification system. Critical Care Medicine 1985 13: 818-29";
}


var helptext="<ul><li> Liver insufficiency - cirrhosis, previous hepatic failure etc.</li><li>New Heart Association Class IV Heart Failure</li><li> Respiratory - severe chronic lung disease, respirator dependency</li><li>Receiving chronic dialysis</li><li>Immunosuppression e.g. chemo, steroids, AIDS</li> <ul>";

function help() {
	return "Immuno= History of chronic organ insufficiency or immunocompromise: " + "<br />" +helptext;
}